package cn.edu.neusoft.food229.fragment;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

import cn.edu.neusoft.food229.R;
import cn.edu.neusoft.food229.adapter.CarAdapter;
import cn.edu.neusoft.food229.adapter.ShopAdapter;
import cn.edu.neusoft.food229.bean.CarBean;
import cn.edu.neusoft.food229.bean.ShopBean;
import cn.edu.neusoft.food229.listener.CarListener;
import cn.edu.neusoft.food229.model.CarModel;

import static android.content.Context.MODE_PRIVATE;

public class Fragment5 extends FragmentBase_229{
    private List<CarBean> list;
    private RecyclerView recyclerView;
    private SharedPreferences sharedPreferences;//简单存储
    private String User_id;
    private CarAdapter adapter;
    private LinearLayoutManager layoutManager;
    private TextView tv,tv_sum;
    private Context context;
    private double summary;
    private View view=null;
    public Fragment5() {
        // Required empty public constructor
    }
    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        this.context=context;
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        context=getActivity();
        view=inflater.inflate(R.layout.fragment5,container,false);


        return view;
    }
    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        System.out.println("-----f5-----");
        sharedPreferences = context.getSharedPreferences("login", MODE_PRIVATE);
        User_id = sharedPreferences.getString("userid", "");
//       summary=getIntent().getStringExtra();

        initRecyclerView(view);


    }

    private void initRecyclerView(View view) {
        recyclerView=view.findViewById(R.id.recyclerView_car);
        tv_sum=view.findViewById(R.id.tvsum);
        layoutManager=new LinearLayoutManager(context);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setHasFixedSize(true);//固定条目高度，提高性能
        CarModel model=new CarModel();
        model.getResult(User_id,new CarListener() {
            @Override
            public void onResponce(List<CarBean> shopBean) {
                adapter=new CarAdapter(context,shopBean);
                recyclerView.setAdapter(adapter);
            }


            @Override
            public void onFail(String msg) {

            }
        });
        layoutManager=new LinearLayoutManager(context);
        recyclerView.setAdapter(adapter);
    }
}
